package com.zpark.it.controller;


import com.zpark.it.param.ProductSearchParam;
import com.zpark.it.pojo.Product;
import com.zpark.it.service.SearchService;
import com.zpark.it.utils.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Title: SearchController
 * @Author Charles
 * @Package com.zpark.it.controller
 * @Date 2023/7/23 16:41
 */
@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/product")
    public R searchProduct(@RequestBody ProductSearchParam productSearchParam){

        return searchService.search(productSearchParam);
    }

    @PostMapping("/save")
    public R saveProduct(@RequestBody Product product) throws IOException {

        return searchService.save(product);
    }

    @PostMapping("/remove")
    public R removeProduct(@RequestBody Integer productId) throws IOException {

        return searchService.remove(productId);
    }

}
